package net.sf.jxls.sample.hall;

/**
 * @Author duhongming
 * @Email 19919902414@189.cn
 * @Date 2018/7/17 14:59
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 *@Company:kedong
 *@Author:杜洪明
 *@Since:2018年7月11日
 *@Version:1.1.0
 */
public class CardBusinessReportService {

    public static List<GroupList<CardBusinessReport>> toGroupData(List<CardBusinessReport> results){
        //按地市分组
        Map<String, List<CardBusinessReport>> groupListByCityName = results.stream()
                //.limit(100)
                .collect(
                        Collectors.groupingBy(CardBusinessReport::getCityName)
                );
        List<GroupList<CardBusinessReport>> groupList = new ArrayList<GroupList<CardBusinessReport>>();
        //分组中加小计
        groupListByCityName.forEach((k,v)->{
            GroupList<CardBusinessReport> cardBusinessReportGroupList = new GroupList<CardBusinessReport>();
            cardBusinessReportGroupList.setGroupList(v);
            groupList.add(cardBusinessReportGroupList);
        });
        return groupList;
    }

    public static CardBusinessReport get(List<CardBusinessReport> v){

        CardBusinessReport cardBusinessReport = new CardBusinessReport();
        cardBusinessReport.setStoreName("总计");
        //营业厅售卡情况
        int openCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenCardMonth));
        cardBusinessReport.setOpenCardMonth(openCardMonth);
        int openCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenCardYear));
        cardBusinessReport.setOpenCardYear(openCardYear);
        int openCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenCardSum));
        cardBusinessReport.setOpenCardSum(openCardSum);
        int cancelCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelCardMonth));
        cardBusinessReport.setCancelCardMonth(cancelCardMonth);
        int cancelCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelCardYear));
        cardBusinessReport.setCancelCardYear(cancelCardYear);
        int cancelCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelCardSum));
        cardBusinessReport.setCancelCardSum(cancelCardSum);
        int supplementCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementCardMonth));
        cardBusinessReport.setSupplementCardMonth(supplementCardMonth);
        int supplementCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementCardYear));
        cardBusinessReport.setSupplementCardYear(supplementCardYear);
        int supplementCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementCardSum));
        cardBusinessReport.setSupplementCardSum(supplementCardSum);
        int changeCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangeCardMonth));
        cardBusinessReport.setChangeCardMonth(changeCardMonth);
        int changeCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangeCardYear));
        cardBusinessReport.setChangeCardYear(changeCardYear);
        int changeCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangeCardSum));
        cardBusinessReport.setChangeCardSum(changeCardSum);

        //开卡详情情况
//        int openPersonalCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenPersonalCardMonth));
//        cardBusinessReport.setOpenPersonalCardMonth(openPersonalCardMonth);
        int openPersonalCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenPersonalCardYear));
        cardBusinessReport.setOpenPersonalCardYear(openPersonalCardYear);
        int openPersonalCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenPersonalCardSum));
        cardBusinessReport.setOpenPersonalCardSum(openPersonalCardSum);
//        int openAnonymousCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenAnonymousCardMonth));
//        cardBusinessReport.setOpenAnonymousCardMonth(openAnonymousCardMonth);
        int openAnonymousCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenAnonymousCardYear));
        cardBusinessReport.setOpenAnonymousCardYear(openAnonymousCardYear);
        int openAnonymousCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenAnonymousCardSum));
        cardBusinessReport.setOpenAnonymousCardSum(openAnonymousCardSum);
//        int openGroupCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenGroupCardMonth));
//        cardBusinessReport.setOpenGroupCardMonth(openGroupCardMonth);
        int openGroupCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenGroupCardYear));
        cardBusinessReport.setOpenGroupCardYear(openGroupCardYear);
        int openGroupCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getOpenGroupCardSum));
        cardBusinessReport.setOpenGroupCardSum(openGroupCardSum);

        //销卡详情情况
//        int cancelPersonalCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelPersonalCardMonth));
//        cardBusinessReport.setCancelPersonalCardMonth(cancelPersonalCardMonth);
        int cancelPersonalCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelPersonalCardYear));
        cardBusinessReport.setCancelPersonalCardYear(cancelPersonalCardYear);
        int cancelPersonalCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelPersonalCardSum));
        cardBusinessReport.setCancelPersonalCardSum(cancelPersonalCardSum);
//        int cancelGroupCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelGroupCardMonth));
//        cardBusinessReport.setCancelGroupCardMonth(cancelGroupCardMonth);
        int cancelGroupCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelGroupCardYear));
        cardBusinessReport.setCancelGroupCardYear(cancelGroupCardYear);
        int cancelGroupCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getCancelGroupCardSum));
        cardBusinessReport.setCancelGroupCardSum(cancelGroupCardSum);

        //补卡详情情况
//        int supplementPersonalCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementPersonalCardMonth));
//        cardBusinessReport.setSupplementPersonalCardMonth(supplementPersonalCardMonth);
        int supplementPersonalCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementPersonalCardYear));
        cardBusinessReport.setSupplementPersonalCardYear(supplementPersonalCardYear);
        int supplementPersonalCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementPersonalCardSum));
        cardBusinessReport.setSupplementPersonalCardSum(supplementPersonalCardSum);
//        int supplementGroupCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementGroupCardMonth));
//        cardBusinessReport.setSupplementGroupCardMonth(supplementGroupCardMonth);
        int supplementGroupCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementGroupCardYear));
        cardBusinessReport.setSupplementGroupCardYear(supplementGroupCardYear);
        int supplementGroupCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getSupplementGroupCardSum));
        cardBusinessReport.setSupplementGroupCardSum(supplementGroupCardSum);

        //换卡详情情况
//        int changePersonalCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangePersonalCardMonth));
//        cardBusinessReport.setChangePersonalCardMonth(changePersonalCardMonth);
        int changePersonalCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangePersonalCardYear));
        cardBusinessReport.setChangePersonalCardYear(changePersonalCardYear);
        int changePersonalCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangePersonalCardSum));
        cardBusinessReport.setChangePersonalCardSum(changePersonalCardSum);
//        int changeGroupCardMonth = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangeGroupCardMonth));
//        cardBusinessReport.setChangeGroupCardMonth(changeGroupCardMonth);
        int changeGroupCardYear = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangeGroupCardYear));
        cardBusinessReport.setChangeGroupCardYear(changeGroupCardYear);
        int changeGroupCardSum = v.stream().collect(Collectors.summingInt(CardBusinessReport::getChangeGroupCardSum));
        cardBusinessReport.setChangeGroupCardSum(changeGroupCardSum);

        return cardBusinessReport;
    }
}
